using micromsg;
using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Network;
using MicroMsg.Protocol;
using MicroMsg.Scene;
using System;
namespace MicroMsg.Plugin.Shake.Scene
{
	public class NetSceneShakeTranImgGet : NetSceneBaseEx<ShakeTranImgGetRequest, ShakeTranImgGetResponse, ShakeTranImgGetRequest.Builder>
	{
		private const string TAG = "NetSceneShakeTranImgGet";
		private const int MAX_TIMES = 3;
		private int mContinueTimes;
		public bool doScene(SKBuiltinBuffer_t skbuiltinBuffer_t_0)
		{
			Log.smethod_4("NetSceneShakeTranImgGet", "doscene in");
			base.beginBuilder();
			this.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0);
			this.mBuilder.Buffer = skbuiltinBuffer_t_0;
			this.mSessionPack.mCmdID = 128;
			base.endBuilder();
			return true;
		}
		protected override void onFailed(ShakeTranImgGetRequest request, ShakeTranImgGetResponse response)
		{
			PackResult lastError = base.getLastError();
			Log.smethod_4("NetSceneShakeTranImgGet", "onFailed in PackResult =" + lastError);
			if (lastError == PackResult.BEEN_CANCELLED)
			{
				return;
			}
			EventCenter.postEvent(EventConst.ON_NETSCENE_SHAKE_ERR, null, null);
		}
		protected override void onSuccess(ShakeTranImgGetRequest request, ShakeTranImgGetResponse response)
		{
			Log.smethod_4("NetSceneShakeTranImgGet", "onSuccess in");
			RetConst ret = (RetConst)response.BaseResponse.Ret;
			if (ret == RetConst.MM_ERR_SHAKE_TRAN_IMG_CONTINUE)
			{
				if (this.mContinueTimes > 3)
				{
					Log.smethod_1("NetSceneShakeTranImgGet", "reach max continue times");
					EventCenter.postEvent(EventConst.ON_NETSCENE_SHAKE_ERR, ret, null);
					return;
				}
				ShakeService.delayToExec(2, delegate
				{
					this.mContinueTimes++;
					this.doScene(response.Buffer);
				});
			}
			else
			{
				if (ret == RetConst.MM_OK)
				{
					EventCenter.postEvent(EventConst.ON_NETSCENE_SHAKE_SUCCESS, null, null);
					return;
				}
			}
			if (ret != RetConst.MM_ERR_SHAKE_TRAN_IMG_CANCEL)
			{
				if (ret != RetConst.MM_ERR_SHAKE_TRAN_IMG_NOTFOUND)
				{
					EventCenter.postEvent(EventConst.ON_NETSCENE_SHAKE_ERR, ret, null);
					return;
				}
			}
			EventCenter.postEvent(EventConst.ON_NETSCENE_SHAKE_ERR, ret, null);
		}
	}
}
